﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using PJ.Business.Partner;
using Microsoft.Practices.Composite.Events;
using PJ.Business.Inventory;

namespace PJ.Presentation.Inventory
{
    public class InventoryItemBasicInfoPresentationModel : IInventoryItemBasicInfoPresentationModel, INotifyPropertyChanged
    {
        private IInventoryItem m_InventoryItem;
        private readonly IInventoryItemProvider m_InventoryProvider;
        public event PropertyChangedEventHandler PropertyChanged = delegate { };

        public InventoryItemBasicInfoPresentationModel(IInventoryItemBasicInfoView view, 
                                    IInventoryItemProvider InventoryProvider, 
                                    IEventAggregator eventAggregator)
        {
            View = view;
            View.Model = this;
            this.m_InventoryProvider = InventoryProvider;
            eventAggregator.GetEvent<InventoryItemChangeEvent>().Subscribe(ChangeInventory);
        }


        public IInventoryItemBasicInfoView View { get; private set; }


        public void ChangeInventory(IInventoryItem inventory)
        {
            InventoryItem = inventory;
        }

        public IInventoryItem InventoryItem
        {
            get { return m_InventoryItem; }
            set
            {
                if (m_InventoryItem != value)
                {
                    m_InventoryItem = value;
                    PropertyChanged(this, new PropertyChangedEventArgs("InventoryItem"));
                }
            }
        }
    }
}
